﻿using System.Runtime.InteropServices;

namespace AMEC.PCSoftware.CommunicationProtocol.CrazyHein.FINS.Command
{
    public enum FINS_MAIN_COMMANDS_T : byte
    {
        IO_MEMORY_AREA_ACCESS = 0x01,
    }

    public enum FINS_SUB_COMMANDS_T : byte
    {
        READ = 0x01,
        WRITE = 0x02,
        FILL = 0x03,
        MULTIPLE_READ = 0x04,
        TRANSFER = 0x05
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct FINS_HEADER_T
    {
        public byte ICF;
        public byte RSV;
        public byte GCT;
        public byte DNA;
        public byte DA1;
        public byte DA2;
        public byte SNA;
        public byte SA1;
        public byte SA2;
        public byte SID;
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct COMMAND_REQUEST_T
    {
        public FINS_HEADER_T header;
        public FINS_MAIN_COMMANDS_T main_command;
        public FINS_SUB_COMMANDS_T sub_command;
        [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 2000, ArraySubType = UnmanagedType.U1)]
        public byte[] data;
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct COMMAND_REQUEST_HEADER_T
    {
        public FINS_HEADER_T header;
        public FINS_MAIN_COMMANDS_T main_command;
        public FINS_SUB_COMMANDS_T sub_command;

        public COMMAND_REQUEST_HEADER_T()
        {
            header = new FINS_HEADER_T() { ICF = 0x80, GCT = 0x02 };
            main_command = FINS_MAIN_COMMANDS_T.IO_MEMORY_AREA_ACCESS;
            sub_command = FINS_SUB_COMMANDS_T.READ;
        }
    }
}
